-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDC-3382] Allow orphan removal to be cancelled #1419
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3765 We use Jira to track the state of pull requests and the versions they got |
c2c5d3d
to
ecc5211
Compare
ecc5211
to
96dbece
Compare
Hmmm, it would be nice to let entities to be safely "transferred" to another parent of the very same entity-type:
However, isn't this change a little broader than that? It looks like the instant the child gets put in any |
@DHager Isn't that the expected behaviour? If the entity is added to another PersistentCollection, it is no longer an orphan and should thus not be deleted? |
Very good catch. |
[DDC-3382] Allow orphan removal to be cancelled
Waiting for @Ocramius ack to merge this to 2.5 branch |
@c960657 : I guess I had the idea that In that case, don't we also need to cancel the removal for orphans that are re-adopted directly by an entity, without involving a
I think there should be a test-case for that, and my guess is that it won't (yet) work. |
Not OK for 2.5.1, as this behavior existed for a lot of versions before that, and even if buggy, a lot of users coded their entity logic according to that. |
According to @Ocramius this pull request give me error when i try to update a collection with a new item. |
@Charlie-Lucas Could you provide steps to reproduce this problem? |
I have a basic relation OneToMany with OrphanRemoval=true.
When i persist the first time my form with the entityManager, i have no errors.
I have no controller logic to handle my collection, just a simple persist of my entity. |
Hi everyone We face an issue with the extensive use of collections and the newly added cancelOrphanRemoval function.
If $entity is 'null' for any reason in add/set this will fail with an exception. A check before to validate $entity is not null is at least helpful before unset. Thanks |
Could you provide a stack trace for this error? It seems that something is setting or adding a null value to the persistent collection. That sounds like a bug to me. |
@c960657 Can you create a test-case for when an entity is removed from a
As I said before, I'm reasonably certain this will highlight a scenario that hasn't been covered yet, where |
I have this exact same issue me thinks stack trace below:
Any help would be greatly appreciated, as this is a mayor blocker for me atm, as i cant get past it (other then circumventing the orphanremoval code) Let me know what steps i can take to help solve this issue. |
The problem occurs because a non-object is added to the PersistentCollection:
I don't know if this is supposed to work, but I don't think so. The documentation states that a "PersistentCollection represents a collection of elements that have persistent state". I believe this excludes non-elements. The below code would throw a similar error even before this change:
So I don't think the bug is in Doctrine 2 but probably in the Symfony form binding code. That being said, it seems reasonable to modify to add() and set() to check for non-object values. Because of BC we have to just silently ignore these (this might change in a future major release). I will prepare a PR for that. |
yes i know its adding a null to the collection, i just cant seem to figure out where, and why, things are going wrong, causing it to end up with this null. Only thing i can do atm is overwrite the PropertyAccessor->getValue function with
To make things atleast function |
temp workaround: in
in
|
When this mergin will be released? It is very necessary. |
Ping... |
@vlastv you must use 2.5 version of doctrine not dev-master |
@Charlie-Lucas 2.5 version does not contain this pr. |
@grachevko sorry i was wrong this PR is only merged on master |
I have a one-to-many relation with orphanRemoval=true.
If I remove an entity from the related collection and add it back, the entity is removed from the database.
The expected behaviour is to leave the entity in the database, because it was present in the PersistentCollection when $em->persist() was called.
This has previously been suggested in DDC-3382, but it was rejected. This PR shows how small a change it is, so I hope the suggestion will be reconsidered in the light of this.